import api.repository.knowledgebase_repository as knowledgebase_repository
from api.model.knowledgebase_model import Knowledgebase
from api.vo.ResponseVo import ResponseVo, ResponsePageVo
from api.vo.form.knowledge_form import KnowledgebaseForm
from api.vo.query.knowledgebase_query import KnowledgebaseQuery


def add(knowledgeForm: KnowledgebaseForm) -> ResponseVo:
    knowledge = Knowledgebase(name=knowledgeForm.name, description=knowledgeForm.description)
    return ResponseVo(data=knowledgebase_repository.add(knowledge))

def disabled(idList: list) -> ResponseVo:
    return ResponseVo(data=knowledgebase_repository.update_status(idList=idList, status="0"))

def enabled(idList: list) -> ResponseVo:
    return ResponseVo(data=knowledgebase_repository.update_status(idList=idList, status="1"))

def list(knowledgebase: KnowledgebaseQuery) -> ResponsePageVo:
    list,count = knowledgebase_repository.list(knowledgebase=knowledgebase)
    return ResponsePageVo(data=list, total=count, page=knowledgebase.page, rows=knowledgebase.rows)

def deletes(idList: list) -> ResponseVo:
    return ResponseVo(data=knowledgebase_repository.delete(idList = idList))

def update(knowledgeForm: KnowledgebaseForm) -> ResponseVo:
    return ResponseVo(data=knowledgebase_repository.update(knowledgeForm))


def exists(name: str, id: str):
    return ResponseVo(data=knowledgebase_repository.exist(name=name, id=id))


def get(id):
    return ResponseVo(data=knowledgebase_repository.get(id=id))